import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
Vue.use(VueRouter)

const Auth = () =>
    import ("@/views/auth/Auth")
const Index = () =>
    import ("@/views/index/Index")
const startCity = () =>
    import ("@/views/index/startCity")
const endCity = () =>
    import ("@/views/index/endCity")
const searchBus = () =>
    import ("@/views/searchbus/searchBus")
const addPassenger = () =>
    import ("@/views/user/addPassenger")
const delPassEnger = () =>
    import ("@/views/user/delPassEnger")
const order = () =>
    import ("@/views/order/Order")
const orderDetail = () =>
    import ("@/views/order/orderDetail")
const orderList = () =>
    import ("@/views/order/orderList")
const paySuccess = () =>
    import ("@/views/order/paySuccess")


const routes = [{
        path: "/",
        redirect: "/Index"
    },
    {
        path: "/Auth",
        name: "Auth",
        meta: {
            title: "授权中"
        },
        component: Auth
    },
    {
        path: "/Index",
        name: "Index",
        meta: {
            title: "首页",
            keepAlive: false
        },
        component: Index,
    },
    {
        path: "/startCity",
        name: "startCity",
        meta: {
            title: "出发地",
            keepAlive: true
        },
        component: startCity
    },
    {
        path: "/endCity",
        name: "endCity",
        meta: {
            title: "目的地",
            keepAlive: true
        },
        component: endCity
    },
    {
        path: "/searchBus",
        name: "searchBus",
        meta: {
            title: "车票查询",
            keepAlive: false
        },
        component: searchBus
    },
    {
        path: "/addPassenger",
        name: "addPassenger",
        meta: {
            title: "新增乘客"
        },
        component: addPassenger
    },
    {
        path: "/order",
        name: "order",
        meta: {
            title: "车票详情",
            keepAlive: false
        },
        component: order
    },
    {
        path: "/orderDetail",
        name: "orderDetail",
        meta: {
            title: "订单详情"
        },
        component: orderDetail
    },
    {
        path: "/orderList",
        name: "orderList",
        meta: {
            title: "订单列表"
        },
        component: orderList
    },
    {
        path: "/paySuccess",
        name: "paySuccess",
        meta: {
            title: "支付成功"
        },
        component: paySuccess
    },
    {
        path: "/delPassEnger",
        name: "delPassEnger",
        meta: {
            title: "删除乘客"
        },
        component: delPassEnger
    }

]


const router = new VueRouter({
    mode: "history",
    routes,
    scrollBehavior(to, from, savePosition) {
        if (savePosition) {
            return savePosition
        } else {
            return { x: 0, y: 0 };
        }
    },
})




router.beforeEach((to, from, next) => {
    next()
})

router.afterEach(to => {
    to.meta.title && (document.title = to.meta.title)
})

export default router